package com.example.love_margin.Mapper;



import com.example.love_margin.Entity.Science;
import com.example.love_margin.Mapper.configuer.DeleteMany;
import com.example.love_margin.Mapper.configuer.SeletPetPicture;
import org.apache.ibatis.annotations.*;


import java.util.List;

@Mapper
public interface ScienceMapper {

    @Insert("INSERT INTO science(science_title,science_time,science_picture,science_message,science_type)values(#{science_title},#{science_picture}" +
            ",#{science_type},#{science_time},#{science_message})")
    int addScience(Science science);

    //删除单条
    @Delete("DELETE FROM science WHERE science_id=#{science_id}")
    int deleteScience(int science_id);

    //批量删除

    @DeleteProvider(type = DeleteMany.class,method = "deleteM")
    int deleteScienceM(String sql);


    //查询多个对象的图片的地址用以删除
    @SelectProvider(type = SeletPetPicture.class,method = "SelectPetP")
    List<String> selectPetAll(String URL);


    //通过id进行修改宠物信息
    @Update("UPDATE science SET science_title=#{science_title},science_picture=#{science_picture},science_time=#{science_time}" +
            "science_type=#{science_type},science_message=#{science_message}" +
            " WHERE science_id = #{science_id}")
    int upScience(Science science);

    //查询单条科普信息
    @Select("SELECT * FROM science WHERE science_id = #{science_id}")
    Science selectOneScienceAll(int pet_id);

    //查询单条科普信息
    //查询数据库前十条数据，id自增的时候，是从id最小的开始到第十条最大
    @Select("select * from science limit 0,2")
    List<Science> selectTen();


    //查询多条科普信息
    @Select("SELECT * FROM science")
    List<Science> selectScienceMany(String science_id);

}
